//
//  AppDelegate.swift
//  HJWeiBo
//
//  Created by 夏航军 on 16/9/22.
//  Copyright © 2016年 夏航军. All rights reserved.
//

import UIKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?


    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        
        //调用方法
        registerNotification()
        
        window = UIWindow(frame: UIScreen.main.bounds)
        
        window?.backgroundColor = UIColor.white
        
        //调试=============================================
        let compose  = HJComposeViewController()
        let nav = UINavigationController(rootViewController: compose)
        window?.rootViewController = nav
        
        //window?.rootViewController = HJUserAccountViewModel.sharedAccountViewModel.userLogin ? HJWelcomeViewController() : HJTabBarViewController()
        
      
        
        window?.makeKeyAndVisible()
        
        
        
        return true
    }

    func registerNotification() {
        //注册通知
        NotificationCenter.default.addObserver(self, selector: #selector(setRootViewController(n:)), name: NSNotification.Name(rawValue:KchangeRootViewController), object: nil)
    }
    
    //实现通知的监听方法
    @objc private func setRootViewController(n : NSNotification) {
        
        print(n.object)
        if n.object == nil {
            
            window?.rootViewController = HJTabBarViewController()
        }else {
            window?.rootViewController = HJWelcomeViewController()
        }
    }
    
    //销毁通知,此处没作用
    deinit {
        NotificationCenter.default.removeObserver(self)
    }
}









